﻿using System;
using System.Collections.Generic;
using System.Text;

using Asp = System.Web;
using Daco.Web.Store;

namespace Daco.Web.UI.WebControls
{
    public class ULManufacture : Asp.UI.WebControls.WebControl
    {
        private IEnumerable<CManufacture> _dataSource = null;
        public IEnumerable<CManufacture> DataSource
        {
            get { return _dataSource; }
            set { _dataSource = value; }
        }

        private CManufacture _selectedManufacture;
        public CManufacture SelectedManufacture
        {
            get { return _selectedManufacture; }
            set { _selectedManufacture = value; }
        }

        private string _title;
        public string Title
        {
            get { return _title; }
            set
            {
                if (!string.IsNullOrEmpty(value) && (string.IsNullOrEmpty(_title) || string.Compare(value, _title, StringComparison.CurrentCultureIgnoreCase) == 0))
                    _title = value;
            }
        }

        public override string ClientID
        {
            get
            {
                return string.Format("DACO_WebControl_ManufactureList_" + this.GetHashCode());
            }
        }

        public override string UniqueID
        {
            get
            {
                return string.Format("DACO$WebControl$ManufactureList$" + this.GetHashCode());
            }
        }

        public ULManufacture()
        {
            //this.Load += new EventHandler(ULManufacture_Load);
        }

        void ULManufacture_Load(object sender, EventArgs e)
        {
            // Get manufacture list
            //_dataSource = CProduct.GetManufactures();
        }

        protected override void Render(Asp.UI.HtmlTextWriter writer)
        {
            writer.WriteLine(@"<div class=""DIVBox"">
                            <div class=""DIVBoxHeader"">
                                <div><h4>{0}</h4></div>
                            </div>
                            <div class=""DIVBoxContent"">
                                <div>", Title);
            writer.WriteLine(@"<ul class=""ULLineHeight150"">");
            foreach (CManufacture manufacture in _dataSource)
            {
                // Write begin LI
                writer.Write(@"<li class=""LISquare"">
                    <a class=""title"" href=""{0}"" title=""{1}"" >{1}</a>", Page.ResolveUrl(string.Format("~/EStore/Catalog.aspx?ml={0}&title={1}", manufacture.ManufactureID, manufacture.EncodedTitle)), manufacture.Name);
                // Write end LI
                writer.WriteLine("</li>");
            }
            writer.WriteLine("</ul>");

            writer.WriteLine(@"</div>
                        </div>
                    </div>");
        }
    }
}
